package com.sxkf.template.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxkf.core.api.vo.R;
import com.sxkf.template.entity.Address;
import com.sxkf.template.service.AddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
* 用户地址表(t_address)表控制层
*
* @author zgc
*/
@Api(tags="地址模块")
@RestController
@RequestMapping("/address")
public class AddressController {
/**
* 服务对象
*/
    @Resource
    private AddressService addressService;
    
    @ApiOperation("创建用户地址")
    @PostMapping("/createAddress")
    public R<Boolean> createAddress(@RequestBody Address address) {
        return R.success(addressService.save(address));
    }
    
    @ApiOperation("更新用户地址")
    @PostMapping("/updateAddress")
    public R<Boolean> updateAddress(@RequestBody Address address) {
        return R.success(addressService.updateById(address));
    }
    
    @ApiOperation("删除用户地址")
    @PostMapping("/deleteAddress")
    public R<Boolean> deleteAddress(@RequestParam String id) {
        return R.success(addressService.removeById(id));
    }
    
    @ApiOperation("查询用户地址")
    @GetMapping("/listAddress")
    public R<IPage<Address>> listAddress(@RequestParam String userId,
                                         @RequestParam Integer pageNo,
                                         @RequestParam Integer pageSize) {
        return R.success(addressService.page(new Page<Address>(pageNo, pageSize), 
                new LambdaQueryWrapper<Address>().eq(Address::getUserId, userId)));
    }
    
}
